home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9961 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  77 lines

  1. Newsgroups: comp.lang.c++
  2. Path: news.sprintlink.net!mv!usenet
  3. From: ENGR@GSSI.MV.COM (Michael Furman)
  4. Subject: Re: Help -- Problem with Protected Class in Borland 4.5
  5. Message-ID: <DnJuwx.9to@mv.mv.com>
  6. Mime-Version: 1.0
  7. Organization: GSSI
  8. Date: Thu, 29 Feb 1996 18:19:44 GMT
  9. References: <4h4fgt$ina@sulawesi.lerc.nasa.gov>
  10. X-Newsreader: WinVN 0.93.10
  11. X-Nntp-Posting-Host: gssi.mv.com
  12.  
  13. In article <4h4fgt$ina@sulawesi.lerc.nasa.gov>, edfollo@lovage.lerc.nasa.gov 
  14. says...
  15. >
  16. >
  17. >I'm using Borland C++ 4.5, trying to create either a DOS target or a EasyWin
  18. >target.  I cannot get the following code to compile:
  19. >
  20. >#include <iostream.h>
  21. >
  22. >class BaseClass
  23. >{
  24. >   public:
  25. >      int a;
  26. >   protected:
  27. >      int b;
  28. >};
  29. >
  30. >
  31. >class UpperClass : public BaseClass
  32. >{
  33. >   public:
  34. >      void print_a() {cout << "\na = " << a;}
  35. >      void print_b() {cout << "\nb = " << b;}
  36. >};
  37. >
  38. >void main()
  39. >{
  40. >   UpperClass x;
  41. >
  42. >   x.a = 1;
  43. >   x.b = 2;
  44. >
  45. >   x.print_a();
  46. >   x.print_b();
  47. >
  48. >}
  49. >
  50. >
  51. >The error I get is:
  52. >
  53. >'BaseClass::b' is not accessible in function main()
  54. >
  55. >
  56. >The code works if I comment out protected. What's wrong here?
  57. >
  58.  
  59. You explicitly forbid access to "b" by declareing it as protected! So what
  60. do you want?
  61.   "public" means that you can access member from everywere;
  62.   "private" - only from member functions of this class;
  63.   "protected" - from member functuons of this class and derived classes
  64.      (if they are not derived "privately") - but not from other functions
  65.       like main.
  66.  
  67.  
  68. -- 
  69. <<< If you received it by E-mail: it is a copy of post to the newsgroup >>>
  70. ---------------------------------------------------------------
  71. Michael Furman,                       (603)893-1109
  72. Geophysical Survey Systems, Inc.  fax:(603)889-3984
  73. 13 Klein Drive - P.O. Box 97          engr@gssi.mv.com 
  74. North Salem, NH 03073-0097            71543.1334@compuserve.com
  75. ---------------------------------------------------------------
  76.  
  77.